package com.financing.platform.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IFpVideoDao;
import com.financing.platform.dto.FpVideoDTO;
import com.financing.platform.service.IFpVideoService;
/**
 * fp_video  
 * 路演视频 业务访问层实现类
 * @author lisu
 *
 */
 
@Repository("fpVideoService")
public class FpVideoServiceImpl implements IFpVideoService{

	@Autowired
	private IFpVideoDao fpVideoDao;

	@Override
	public int insert(FpVideoDTO fpVideo) throws SQLException {
		return fpVideoDao.insert(fpVideo);
	}

	@Override
	public void update(Map<String, Object>  map) throws SQLException {
		fpVideoDao.update(map);
	}

	@Override
	public void updateForce(FpVideoDTO fpVideo) throws SQLException {
		fpVideoDao.updateForce(fpVideo);
	}

	@Override
	public void delete(Integer id) throws SQLException {
		fpVideoDao.delete(id);
	}
	
	@Override
	public List<FpVideoDTO> queryList(FpVideoDTO fpVideo) throws SQLException {
		
		String orderParameter = fpVideo.getOrderParameter();
		//01 添加时间02修改时间03 真实数据
		if("01".equals(orderParameter)){
			orderParameter = "CREATE_DATE";
 		}else if("02".equals(orderParameter)){
 			orderParameter = "UPDATE_DATE";
 		}else if("03".equals(orderParameter)){
 			orderParameter = "ACTUAL_BROWSE_VOLUME";
 		}else{
 			orderParameter = "id";
 		}
		fpVideo.setOrderParameter(orderParameter);
		
		
		String orderType = fpVideo.getOrderType();
		//01 降序 02 升序
		if("01".equals(orderType)){
			orderType = "desc";
 		}else if("02".equals(orderType)){
 			orderType = "asc";
 		}else{
 			orderType = "desc";
 		}
		fpVideo.setOrderType(orderType);
		 			
		return fpVideoDao.queryList(fpVideo);
	}

	@Override
	public int queryListCount(FpVideoDTO fpVideo) throws SQLException {
		return fpVideoDao.queryListCount(fpVideo);
	}

	@Override
	public FpVideoDTO loadById(Integer id) throws SQLException {
		return fpVideoDao.loadById(id);
	}
 	@Override
	public FpVideoDTO queryListGetFirst(FpVideoDTO fpVideo)
			throws SQLException {
		 List<FpVideoDTO> queryList = queryList(fpVideo);
		 if(queryList==null||queryList.size()==0){
			 return new FpVideoDTO();
		 }
		 return queryList.get(0);
	}

	@Override
	public void updateFpVideoPassword(FpVideoDTO fpVideo) throws SQLException {
		fpVideoDao.updateFpVideoPassword(fpVideo);
	}

	@Override
	public FpVideoDTO queryVideoInfo(FpVideoDTO fpVideo) throws SQLException {
		return fpVideoDao.queryVideoInfo(fpVideo);
	}

	@Override
	public void updateFpVideoForProduct(Integer oldId) throws SQLException {
		fpVideoDao.updateFpVideoForProduct(oldId);
	}
}
